﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teriri.File.Client.Maui.Model;
using TouchSocket.Core;

namespace Teriri.File.Client.Maui.Helper
{
    public class FileProcessHelper
    {
        private readonly static List<FileProcessInfo> FileProcessInfos = new(); 

        /// <summary>
        /// 创建信息
        /// </summary>
        public static FileProcessInfo Create(string fileName , FileProcessType type) 
        {
            var uploadInfo = new FileProcessInfo()
            {
                Id = Guid.NewGuid().ToString(),
                Name = fileName,
                ProcessType = type,
                StartTime = DateTime.Now
            };

            FileProcessInfos.Add(uploadInfo);
            return uploadInfo;
        }

        /// <summary>
        /// 读取信息
        /// </summary>
        public static List<FileProcessInfo> Read(FileProcessType type, int maxLength = 20, bool needReverse = true)
        {
            var newList = FileProcessInfos.Where(a => a.ProcessType == type).MapList<FileProcessInfo>();

            if (needReverse)
                newList.Reverse();

            var result = newList.Take(maxLength).ToList();
            return result;
        }
    }
}
